import {base,getOption} from './config'
import cookie from 'react-cookies'



// eslint-disable-next-line import/no-anonymous-default-export
export default {
    //登录，post
    async loginApi(params){
        const option=getOption('post')
        return await fetch(`${base}/loginByPassword?email=${params.account}&password=${params.password}`,option
        ).then((response)=>{
            return response.json()
        }).then((body)=>{
            console.log(body)
            return body;
        }).catch((err)=>{
            console.log('服务器登录出错辣:',err)
        })
    },
    //登录后获取用户信息，get
    async getUserInfoApi(params){
        const option=getOption('get')
        return await fetch(`${base}/findUser/?id=${cookie.load('user-token')}`,option).then((response)=>{
            return response.json()
        }).then((body)=>{
            console.log(body)
            return body
        }).catch((err)=>{
            console.log('服务器获取用户信息出错啦',err)
        })
    },
    //修改密码,post
    async changePwdApi(params){
        const option=getOption('post',params,{"token":cookie.load("usertoken")})
        return await fetch(`${base}/api/###`,option).then((response)=>{
            return response.json()
        }).then((body)=>{
            console.log(body)
            return body
        }).catch((err)=>{
            console.log('服务器修改密码出错啦',err)
        })
    },
    //发送验证码,get
    async sendMimeMailApi(parpams){
      const option=getOption('get');
      return await fetch(`${base}/sendMimeMail?email=${parpams.account}`,option).then((response)=>{
          return response.json()
      }).then((body)=>{
          console.log(body)
          return body
      }).catch((err)=>{
          console.log('服务器发送验证码出错拉',err)
      })
    },
    //退出登录，get
    async loginOutApi(parpams){
        const option=getOption('get');
        return await fetch(`${base}/logout`,option).then((response)=>{
            return response.json()
        }).then((body)=>{
            console.log(body)
            return body
        }).catch((err)=>{
            console.log('服务器退出登录出错拉',err)
        })
    }
}